/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package me.tomato3017.plugins.epicmusic.commands;

import java.util.List;
import me.tomato3017.plugins.epicmusic.EpicMusic;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

/**
 *
 * @author Anthony Kirksey <Anthony.Kirksey@gmail.com>
 */
public class EpicMusicMainCE implements CommandExecutor {
    EpicMusic plugin;

    public EpicMusicMainCE(EpicMusic plugin) {
        this.plugin = plugin;
    }

    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if(!(sender instanceof Player)){
            return false;
        }
        
        Player player = (Player) sender;
        
        if(args.length == 0){
            return false;
        }
        
        if(args[0].equals("aliases")){
            List<String> aliases = EpicMusic.getConfigManager().getAliasList();
            int pages = (int) Math.ceil(aliases.size() / 10.0);
            int page = 1;
            int start;
            int end;
            String output = ChatColor.GREEN + "Aliases: " + ChatColor.RED;
            
            
            try {
                page = Integer.parseInt(args[1]);
                if(page > pages)
                    return false;
            } 
            catch (Exception ex) {
                page = 1;
            }
            
            start = (page - 1) * 10;
            end = ((start + 11) > aliases.size()) ? 10 : aliases.size() - start;
            
            int count;
            boolean firstalias = true;
            for(count = 0; count < end; count++){
                if(firstalias){
                    output = output.concat(aliases.get(count));
                    firstalias = false;
                }
                else{
                    output = output.concat(", " + aliases.get(count));
                }
            }
            
            EpicMusic.sendPlayerMessage(player, output);
            return true;
        }
        
        return false;
    }
}